#include "stdafx.h"
#include "main_form.h"
#include "canvas.h"
#include "control_tree.h"
#include "xml_tree.h"
#include "attr_tree.h"

const std::wstring MainForm::kClassName = L"Controls";

MainForm::MainForm()
{
}


MainForm::~MainForm()
{
}

std::wstring MainForm::GetSkinFolder()
{
	return L"plant_tree";
}

std::wstring MainForm::GetSkinFile()
{
	return L"main_form.xml";
}

std::wstring MainForm::GetWindowClassName() const
{
	return kClassName;
}

ui::Control* MainForm::CreateControl(const std::wstring& pstrClass)
{
	ui::Control* control = nullptr;
	if (pstrClass == L"Canvas")
		control = new Canvas;
	else if (pstrClass == L"ControlTree")
		control = new ControlTree;
	else if (pstrClass == L"XmlTree")
		control = new XmlTree;
	else if (pstrClass == L"AttrTree")
		control = new AttrTree;
	return control;
}

void MainForm::InitWindow()
{
	m_pCanvas = static_cast<Canvas*>(FindControl(L"canvas"));
	m_pTreeControl = static_cast<ControlTree*>(FindControl(L"control_tree"));
	m_pTreeXml = static_cast<XmlTree*>(FindControl(L"xml_tree"));
	m_pTreeAttr = static_cast<AttrTree*>(FindControl(L"attr_tree"));

	m_pTreeControl->InitTree(m_pCanvas);
	m_pTreeXml->InitTree(m_pCanvas);
	m_pTreeAttr->InitTree(m_pCanvas);
	m_pCanvas->InitCanvas(m_pTreeXml, m_pTreeAttr);
}

LRESULT MainForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	PostQuitMessage(0L);
	return __super::OnClose(uMsg, wParam, lParam, bHandled);
}

